home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 535 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: bs@research.att.com
  3. Newsgroups: comp.std.c++
  4. Subject: Returning void
  5. Date: 25 Feb 1996 16:44:40 GMT
  6. Organization: ?
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <199602250134.SAA02280@ncar.ucar.EDU>
  9. NNTP-Posting-Host: taumet.eng.sun.com
  10. Content-Type: text
  11. Content-Length: 1786
  12. Originator: clamage@taumet
  13.  
  14. Paul D. DeRocco <pderocco@ix.netcom.com> writes:
  15.  
  16.  > The C++ standard doesn't allow a return statement with an expression to 
  17.  > be used in a function whose return type is void.
  18.  > 
  19.  > I suggest that it should be legal to return a void expression from a 
  20.  > function whose type is void. Why? It can be useful in templates. 
  21.  > Consider the following:
  22.  > 
  23.  >     template <class T, class R> class Functor {
  24.  >     public:
  25.  >         R& operator()() { return (obj.*mem)(); }
  26.  >         Functor(T& o, R& (T::*m)()): obj(o), mem(m) {}
  27.  >     private:
  28.  >         T& obj;
  29.  >         R& (T::*mem)();
  30.  >     }
  31.  > 
  32.  > This defines a functor containing a pointer to an object to be operated 
  33.  > on, and a pointer to a member function defined for that object. It 
  34.  > should work for any member function that takes no arguments and returns 
  35.  > a result. Unfortunately, it won't work for a member function that 
  36.  > returns void. If return were modified as described above, this function 
  37.  > template would work for member functions that return void as well.
  38.  
  39. I have written a note to the committee formally proposing this. The reason
  40. stated was roughly the one above. In addition - and for the same reason -
  41. I proposed to allow an expression of type void to be used as the argument
  42. of a function taking no argument.
  43.  
  44. There is no guarantee that the committee will accept this or even that the
  45. committee will consider it (though clearly I think the committee ought to).
  46.  
  47.     - Bjarne
  48. [ To submit articles: Try just posting with your newsreader.
  49.               If that fails, use mailto:std-c++@ncar.ucar.edu
  50.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  51.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  52.   Comments? mailto:std-c++-request@ncar.ucar.edu
  53. ]
  54.